<meta charset="utf-8">
<title>Aula sobre o campo combo</title>


<?php
	if (isset($_POST['envia'])) {
		$pizza = $_POST['pizza'];

		if ($pizza == 'sim') {
			$sabor = $_POST['sabor'];

			if (!empty($sabor)) {
				$contar = count($sabor);
				if ($contar > 3) {
					echo "Por favor, selecionar até 3 sabores";
				}else{
					$sabor = implode(', ', $sabor);
					echo $sabor;
				}
			}else {
				echo "Ok";
			}

		}
		elseif($pizza == 'nao'){
			echo "Ok";

		}
	}

?>

<form name="form" action="" method="post">
	<fieldset>
		<label>
			<select name="pizza">
				<option value="" disabled="disabled">Você quer uma pizza?</option>
				<option value="sim">Sim</option>
				<option value="nao">Não</option>
			</select>
		</label>
		<br />
		<label>
			<select name="sabor[]" multiple="multiple" size="6">
				<option value="" disabled="disabled">Selecione até 3 sabores</option>
				<option value="calabresa">Calabresa</option>
				<option value="frango">Frango</option>
				<option value="palmito">Palmito</option>
				<option value="musaarela">Musaarela</option>
				<option value="bacon">Bacon</option>
			</select>
			<br />
			<input type="submit" name="envia" value="pedir" >
		</label>
	</fieldset>
</form>


